﻿using WpfWordsLearner;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using WpfWordsLearner.Model;
using System.Collections.Generic;

namespace TestProjectWords
{


	/// <summary>
	///This is a test class for WordsManagerTest and is intended
	///to contain all WordsManagerTest Unit Tests
	///</summary>
	[TestClass()]
	public class WordsManagerTest
	{
		private TestContext testContextInstance;

		/// <summary>
		///Gets or sets the test context which provides
		///information about and functionality for the current test run.
		///</summary>
		public TestContext TestContext
		{
			get
			{
				return testContextInstance;
			}
			set
			{
				testContextInstance = value;
			}
		}

		#region Additional test attributes
		// 
		//You can use the following additional attributes as you write your tests:
		//
		//Use ClassInitialize to run code before running the first test in the class
		//[ClassInitialize()]
		//public static void MyClassInitialize(TestContext testContext)
		//{
		//}
		//
		//Use ClassCleanup to run code after all tests in a class have run
		//[ClassCleanup()]
		//public static void MyClassCleanup()
		//{
		//}
		//
		//Use TestInitialize to run code before running each test
		//[TestInitialize()]
		//public void MyTestInitialize()
		//{
		//}
		//
		//Use TestCleanup to run code after each test has run
		//[TestCleanup()]
		//public void MyTestCleanup()
		//{
		//}
		//
		#endregion


		/// <summary>
		///A test for GetWordsListFromFile
		///</summary>
		[TestMethod()]
		public void GetWordsListFromFileTest()
		{
			WordsManager_Accessor target = new WordsManager_Accessor();
			string file = string.Empty;
			List<WordsModel> expected = null;
			List<WordsModel> actual;
			actual = target.GetWordsListFromFile("f:\\import.txt");
			Assert.AreNotEqual(expected, actual);
		}


		[TestMethod()]
		public void TestParallel()
		{
			List<Item> items = new List<Item>();
			List<int> range = new List<int>(new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 });

			for (int i = 1; i <= 1000; i++)
			{
				items.Add(new Item() { Id = i, Name = i.ToString() });
			}

			Console.WriteLine("Task begin");

			System.Threading.Tasks.Parallel.ForEach(items, item =>
				{
					if (range.Contains((item.Id / 100)))
					{
						Console.WriteLine(item.Id);
					}

				});

			Console.WriteLine("Task end");
		}

		public class Item
		{
			public int Id { get; set; }
			public string Name { get; set; }
		}
	}
}
